#!/bin/sh
###############################################################################
##  Author    : yanjintao
##  Name      : edw_phoenix_load_data.sh
##  Functions : Construct the interface of phoenix
##  Purpose   : Construct the interface of phoenix
##  Revisions or Comments
##  VER        DATE        AUTHOR           DESCRIPTION
##---------  ----------  ---------------  ------------------------------------ 
##  1.0      2018-12-14  yanjintao        1. CREATED THIS SHELL.
###############################################################################

. ${0%`basename ${0}`}edw_parm.sh
. ${0%`basename ${0}`}edw_func.sh

function PHOENIX_INDEX_TOOL(){
  hbase org.apache.phoenix.mapreduce.index.IndexTool --data-table "${1}" --index-table ${2} --output-path ASYNC_IDX_HFILES  --direct
}

for tab_name in "DEPB_INFO" "LOAB_INFO" "LOAF_INFO" "MOAB_INFO" "EOAB_INFO" "EOAF_INFO" "TOAB_INFO" "TOAF_INFO" ;do

    LOGGER "INFO" "Begin to start load data into hbase by using phoenix...."

    V_GROUP="INDEX_${tab_name:0:4}_GROUP"
    PHOENIX_INDEX_TOOL ${tab_name} ${V_GROUP}
    LOGGER "INFO" "Success to  load data into hbase by using phoenix!"

    while true;do
        V_QUERY="select INDEX_STATE from SYSTEM.CATALOG where TABLE_NAME='${V_GROUP}' and COLUMN_NAME is null;"
        echo ${V_RESULT}
        V_RESULT=$(${V_RUN_PHOENIX_SQL} -q "${V_QUERY}")
        if [[ ${V_RESULT} != "'a'" ]]; then
            sleep 60
        else
            break
        fi
    done
done


if [[ $? -ne 0 ]]; then
    exit 1
    LOGGER "INFO" "fail to load data into hbase , please check!!!"
 else
    exit 0 
fi 







